package kisti.lod.classification.group;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

import kisti.lod.classification.FileFactory;

public class Groups {
	
	public static final String GROUP_FOLDER = "predicate-groups";
	protected HashMap<String, Group> groups = new HashMap<String, Group>();
	
	public Groups() throws IOException {
		createGroups();
	}
	
	/**
	 * Parses the group folder for files and creates groups containing
	 * the URIs of each file
	 * @throws IOException 
	 */
	public void createGroups() throws IOException {
		File[] files = FileFactory.getGroupFolder().listFiles();
		for(File file : files) {
			//create new group with filename as groupname
			Group group = new Group(file.getName());
			
			BufferedReader br = new BufferedReader(new FileReader(file));
			String line;
			while((line = br.readLine()) != null) {
				group.addPredicate(line);
			}
			groups.put(file.getName(), group);
		}
	}
	
	public HashMap<String, Group> getGroups() {
		return groups;
	}
}
